#!/usr/bin/python
# encoding: utf-8
'''
@File    :   code.py
@Time    :   2020/03/11 21:54:19
@Author  :   fangkaijin 
@Version :   1.0
@Contact :   fangkaijin@gmail.com
@License :   杭州移动互联
@Desc    :   None
'''

# 导入库包

import sys, os
import subprocess
import progressbar
import pexpect
import logging
from subprocess import call

command = ['ffmpeg',
           '-i',
           'media/1.wav',
           '-i',
           'media/2.wav',
           '-filter_complex',
           '[0:0] [1:0] concat=n=2:v=0:a=1 [a]',
           '-map',
           '[a]',
           'media/merge.wav']

def exec_ffmpeg(command):
    try:
        subprocess.run(command)
    except subprocess.CalledProcessError as err:
        raise FFmpegException(err.returncode, err.cmd, err.output)


class FFmpegException(Exception):
    '''
    subprocess 执行 python 命令抛出的自定义异常
    '''
    def __init__(self, code, cmd, output=None):
        self.code = code
        self.cmd = cmd
        self.putput = output

    def __str__(self):
        return 'ffmpeg命令 %s 执行出错，错误码：%d .' % (self.cmd, self.code)
